#ifndef _CGI_ACTION_H_
#define _CGI_ACTION_H_
#include <string>
#include <map>
#include <json/json.h>
#include "type_def.h"

namespace cgi{

class CgiAction
{
public:
	enum OutType
	{
		TEXT = 0,
		XML = 1,
		JSON = 2,
		HTML = 3
	};
public:
	CgiAction(void);
	virtual ~CgiAction(void);
	virtual int doAction() = 0;
	virtual int init() = 0;
	int proc();
	void render(OutType type, const Json::Value& dataJson);
	void redirect(const std::string& sUrl);
	bool isGet(){return m_bRequestGet;}
	bool isPost(){return !m_bRequestGet;}
	void setCookie(const std::string& sKey, const std::string& sValue, const std::string& sDomain, int iExpired = 0);
	bool parseUploadFile(FileFormList& store);
public:
	std::map<std::string, std::string> GET;
	std::map<std::string, std::string> POST;
	std::map<std::string, std::string> COOKIES;
	std::map<std::string, std::string> ENV;
	std::string POST_DATA;
	std::string QUERY_STRING;
	bool m_bRequestGet;
private:
	void buildResponse(std::string& store, const Json::Value& sBody);
private:
	std::map<std::string, std::string> m_mapResponse;
	bool m_bInit;
};

}
#endif //_CGI_ACTION_H_